package bszt.honor;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Code04_1 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextLine()) {
            String[] s = sc.nextLine().split(" ");
            boolean res = check(s);
            System.out.print(res);
        }
    }

    private static boolean check(String[] s) {
        int n = s.length;
        int[] flg = {1, 0};

        for (int i = 0; i < n - 1; i++) {
            String a = s[i], b = s[i + 1];
            if (a.length() == b.length()) {
                flg[0] = 0;
                break;
            }
        }

        int[] sz = new int[n];
        for (int i = 0; i < n; i++) {
            sz[i] = s[i].length();
        }

        Map<Integer, Integer> d = new HashMap<>();
        for (int num : sz) {
            d.put(num, d.getOrDefault(num, 0) + 1);
        }

        if (sz[0] == sz[n - 1] && d.get(sz[0]) == 2) {
            flg[1] = 1;
        }

        return Math.max(flg[0], flg[1]) >= 1;
    }
}
